home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
tex
/
wd2latex.zip
/
WD2LATEX.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1991-02-19
|
15KB
|
458 lines
program translate_latex (input, output);
uses crt, dos, turbo3;
const
linefeed = ^J;
carriagereturn = ^M;
escape = ^[;
emptystring = ^@;
ctrl_A = ^A;
space = ' ';
si = ^O; {Condensed print command}
so = ^N; {Enlarged print command}
DC2 = ^R; {Cancel condensed print}
DC4 = ^T; {Cancel enlarged print}
type
textfil = text;
filespec = string[13];
string79 = string[79];
greek = set of 224..234; {IBM PC Hi ASCII Characters}
var
inputfile, outputfile : textfil;
filename : string79;
ch : char;
testio : integer;
success, needsource, flag_bold : boolean;
{---------------------------------------------------------------------------}
procedure clean_window (x1, y1, x2, y2: integer);
begin
window (x1, y1, x2, y2);
clrscr;
window (1, 1, 80, 25);
end;
{---------------------------------------------------------------------------}
procedure Set_Video (attribute: integer);
var
blinking, {number to add for blinking}
bold : integer; {number to add for bold}
begin
blinking := (attribute and 4) * 4; { set blinking color based on MSB}
if (attribute and 1) = 1 then {set reverse video}
begin
bold := (attribute and 2) * 7;
TextColor (1 + blinking + bold);
TextBackground (3);
end
else {set normal video colors}
begin
bold := (attribute and 2) * 5 div 2;
TextColor (7 + blinking + bold);
TextBackground (0);
end;
end;
{---------------------------------------------------------------------------}
procedure put_string (out_string: string79;
line, col, attrib: integer);
begin
set_video (attrib);
GotoXY (col, line);
write (out_string);
set_video (0);
end;
{---------------------------------------------------------------------------}
procedure put_centered_string (out_string: string79;
line, attrib: integer);
begin
put_string (out_string, line, 40 - length (out_string) div 2, attrib);
end;
{---------------------------------------------------------------------------}
procedure put_prompt (out_string: string79;
line, col: integer);
begin
GotoXY (col, line);
Clreol;
put_string (out_string, line, col, 3);
end;
{---------------------------------------------------------------------------}
procedure get_string (var in_string: string79;
line, col, attrib,
str_length: integer);
const
bell = 7;
back_space =8;
carriage_return = 13;
escape = 27;
right_arrow = 77;
var
oldstr : string79;
in_char : char;
I : integer;
begin
oldstr := in_string;
put_string (in_string, line, col, attrib);
for I := length (in_string) to str_length - 1 do
put_string (' ', line, col + I, attrib);
GotoXY (col, line);
read (kbd, in_char);
if ord (in_char) <> carriage_return then
in_string := '';
while ord (in_char) <> carriage_return do
begin
if ord (in_char) = back_space then
begin
if length (in_string) > 0 then
begin
in_string[0] := chr(length (in_string) - 1);
write (chr(back_space));
write (' ');
write (chr(back_space));
end;
end
else if ord(in_char) = escape then
begin
read (kbd, in_char);
if ord (in_char) = right_arrow then
begin
if length (oldstr) > length (in_string) then
begin
in_string[0] := chr(length (in_string) + 1);
in_char := oldstr[ord(in_string[0])];
in_string[ord(in_string[0])] := in_char;
write (in_char);
end
end
else
write (chr(bell));
end
else if length (in_string) < str_length then
begin
in_string[0] := chr(length (in_string) + 1);
in_string[ord(in_string[0])] := in_char;
write (in_char);
end
else
write (chr(bell));
read (kbd, in_char);
end;
put_string (in_string, line, col, attrib);
for I := length (in_string) to str_length - 1 do
put_string (' ', line, col + I, 0);
end;
{---------------------------------------------------------------------------}
procedure get_prompted_string (var in_string: string79;
inattr, str_length: integer;
strdesc: string79;
descline, desccol: integer;
prompt: string79;
prline, prcol: integer);
{sample call:
get_prompted_string (NAME, 1 ,30, 'Student Name: ', 10, 2,
'Enter students'' full name.', 24, 2);
}
begin
put_string (strdesc, descline, desccol, 2);
put_prompt (prompt, prline, prcol);
get_string (In_string, descline, desccol + length (strdesc),
inattr, str_length);
put_string (strdesc, descline, desccol, 0);
end;
{---------------------------------------------------------------------------}
procedure read_char;
begin
read(inputfile,ch)
end;
{---------------------------------------------------------------------------}
procedure ask_latex_command(ch: char);
var
latex_command: string79;
begin
latex_command := '';
clean_window (1, 13, 80, 25);
put_string ('Help! I don''t know LaTex for ', 15, 2, 2);
put_string (ch, 15, 31, 3);
get_prompted_string (latex_command, 1, 50, 'Enter LaTex equivalent: ',
17, 2, 'Enter Latex command as well as queried character', 24, 2);
write(outputfile, latex_command);
clean_window (1, 13, 80, 25);
put_centered_string ('Please wait: I''m still translating ', 18, 2);
end;
{---------------------------------------------------------------------------}
procedure super_or_sub; {Process Super- and Subscripts}
begin
read_char;
case ch of
'0', emptystring : write (outputfile, '$^{');
'1', ctrl_A : write (outputfile, '$_{');
end; {* case *}
end;
{---------------------------------------------------------------------------}
procedure h_tab; {This filters out printer htab codes}
begin
read_char;
read_char;
write(outputfile, space);
end;
{---------------------------------------------------------------------------}
procedure ESC_rubbish; {All printer codes not translated}
begin
if ch = 'K' then
begin
read_char; read_char
end
else
read_char
end;
{---------------------------------------------------------------------------}
procedure escape_char; {Escape precedes a lot of printer codes}
begin
read_char;
case ch of
'4': write(outputfile,'{\it '); {request italics}
'5': write(outputfile,'\/}'); {end italics}
'E': write(outputfile,'{\bf '); {select bold face}
'F': write(outputfile,'}'); {close braces}
'g': write(outputfile,'{\sc '); {request small caps}
'p', 'C', 'J', 'K': ESC_rubbish; {unwanted esc code}
'T': write(outputfile,'}$'); {request math mode}
'S': super_or_sub; {request super/subscript}
'$': h_tab; {remove horizontal tab}
end; (* case *)
end;
{---------------------------------------------------------------------------}
procedure greek_char;
begin
case ord(ch) of